Setting the Geometry of the Curve
After your call to theGXNewShape
function, youraCurveShape
variable contains a reference to a new curve shape. Unfortunately, the initial value
of your curve's geometry property results in a somewhat disappointing curve--a very small "curve" that actually consists of a single point.To change your curve shape into something a little more interesting, you must change the value of its geometry property. Before you make the appropriate changes, you need a little more information about the geometry property.
For all of the shape types, the geometry property represents the graphic structure of the shape. For curve shapes in particular, the geometry property contains three coordinate pairs; each pair is called a geometric point.
When you want to specify a geometric point, you can use a point structure, as defined by the
- The first geometric point specifies where the curve begins.
- The second geometric point specifies an off-curve control point that determines the tangents of the curve.
- The third geometric point specifies where the curve ends.
gxPoint
data type provided by QuickDraw GX:
struct gxPoint { Fixed x; /* x-coordinate */ Fixed y; /* y-coordinate */ }TheFixed
data type represents a fixed-point number. AFixed
value contains 32 bits--16 bits to the left of the decimal place and 16 bits to the right of the decimal place. TheGXIntToFixed
macro converts an integer to a fixed-point value by shifting the integer 16 points to the left:
#define GXIntToFixed(a) ((Fixed)(a) << 16)QuickDraw GX provides theff
macro as a convenient alias to theGXIntToFixed
macro:
#define ff(a) GXIntToFixed(a)Now, you're ready to change the geometry of your curve shape into something a little more interesting.QuickDraw GX represents the geometry of a single curve shape using the curve structure, as defined by the
gxCurve
data type:
struct gxCurve { struct gxPoint first; /* first point */ struct gxPoint control; /* control point */ struct gxPoint last; /* last point */ };Using this data type, define the geometric points for your curve:
gxCurve aCurveGeometry = {{ff(40), ff(120)}, /* first point */ {ff(100), ff(0)}, /* control point */ {ff(200), ff(120)}};/* last point */Once you have defined a curve structure, use theGXSetCurve
function to
copy the values from the curve structure into the geometry property of your curve shape:
GXSetCurve(aCurveShape, &aCurveGeometry);There are two ways you can think about the geometry of a curve. You can think of a curve geometry as a structure containing three geometry points, or you can think of a curve geometry in a more visual fashion. Figure 2-3 shows both.Figure 2-3 Two views of a curve geometry
Note that the curve doesn't actually intersect the off-curve control point (which is drawn as a small square in Figure 2-3). This is because QuickDraw GX creates a Bézier curve, using the off-curve control points to define the tangents of the curve.
Now that you've created and defined your curve shape, you can use the supporting objects (the style, ink, and transform objects) to specify various modifications to how QuickDraw GX draws the curve.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help